﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Utility.BehaviourTree
{
	public class RepeaterNode : DecoratorNode
	{
		int count = 0;
		int num = 0;

		/// <summary>
		/// Negative count for infinite loop
		/// </summary>
		/// <param name="count"></param>
		public RepeaterNode (int count)
		{
			this.count = count;

		}

		protected override Status OnUpdate ()
		{
			switch (ChildNode.Update ())
			{
				case Status.Success:
				case Status.Failure:
					num++;
					break;
				case Status.Running:
					break;
			}

			return count < 0 || num < count ? Status.Running : Status.Success;

		}

		protected override void OnReset ()
		{
			base.OnReset ();
			num = 0;
		}
	}
}